package com.menu.system.service.impl;

import java.util.List;
import com.menu.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.menu.system.mapper.MenuProductsAttributeMapper;
import com.menu.system.domain.MenuProductsAttribute;
import com.menu.system.service.IMenuProductsAttributeService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 产品公有属性Service业务层处理
 *
 * @author ruoyi
 * @date 2024-06-28
 */
@Service
public class MenuProductsAttributeServiceImpl implements IMenuProductsAttributeService
{
    @Autowired
    private MenuProductsAttributeMapper menuProductsAttributeMapper;



    /**
     * 查询产品公有属性
     *
     * @param attributeId 产品公有属性主键
     * @return 产品公有属性
     */
    @Override
    public MenuProductsAttribute selectMenuProductsAttributeByAttributeId(Long attributeId)
    {
        return menuProductsAttributeMapper.selectMenuProductsAttributeByAttributeId(attributeId);
    }

    /**
     * 查询产品公有属性列表
     *
     * @param menuProductsAttribute 产品公有属性
     * @return 产品公有属性
     */
    @Override
    public List<MenuProductsAttribute> selectMenuProductsAttributeList(MenuProductsAttribute menuProductsAttribute)
    {
        return menuProductsAttributeMapper.selectMenuProductsAttributeList(menuProductsAttribute);
    }

    /**
     * 新增产品公有属性
     *
     * @param menuProductsAttribute 产品公有属性
     * @return 结果
     */
    @Override
    @Transactional
    public int insertMenuProductsAttribute(MenuProductsAttribute menuProductsAttribute)
    {
        menuProductsAttribute.setCreateTime(DateUtils.getNowDate());
        if(menuProductsAttribute.getParentId().equals(0)){
            menuProductsAttribute.setAncestors("0");
        }else {
            MenuProductsAttribute menuProductsAttribute1=new MenuProductsAttribute();
            menuProductsAttribute1.setAttributeId(menuProductsAttribute.getParentId());
            List<MenuProductsAttribute> menuProductsAttributes = menuProductsAttributeMapper.selectMenuProductsAttributeList(menuProductsAttribute1);
            menuProductsAttribute.setAncestors(menuProductsAttributes.get(0).getAncestors()+menuProductsAttribute.getParentId());

        }
        return menuProductsAttributeMapper.insertMenuProductsAttribute(menuProductsAttribute);
    }

    /**
     * 修改产品公有属性
     *
     * @param menuProductsAttribute 产品公有属性
     * @return 结果
     */
    @Override
    public int updateMenuProductsAttribute(MenuProductsAttribute menuProductsAttribute)
    {
        menuProductsAttribute.setUpdateTime(DateUtils.getNowDate());
        return menuProductsAttributeMapper.updateMenuProductsAttribute(menuProductsAttribute);
    }

    /**
     * 批量删除产品公有属性
     *
     * @param attributeIds 需要删除的产品公有属性主键
     * @return 结果
     */
    @Override
    public int deleteMenuProductsAttributeByAttributeIds(Long[] attributeIds)
    {
        return menuProductsAttributeMapper.deleteMenuProductsAttributeByAttributeIds(attributeIds);
    }

    /**
     * 删除产品公有属性信息
     *
     * @param attributeId 产品公有属性主键
     * @return 结果
     */
    @Override
    public int deleteMenuProductsAttributeByAttributeId(Long attributeId)
    {
        return menuProductsAttributeMapper.deleteMenuProductsAttributeByAttributeId(attributeId);
    }
}
